package com.lqq.view;

import com.lqq.componment.HBox;
import com.lqq.domain.ApplicationDetails;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Details {
    public static void show(){
        ApplicationDetails details=new ApplicationDetails("计信学院 报告厅 预约申请表","研习答辩","202",
                "计信学院","2022-9-29","2022-9-30","2022-9-29","success");
        JFrame jf=new JFrame();
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(700,550);
        jf.setVisible(true);
        jf.setTitle("预约详情");
        jf.setLocationRelativeTo(null);

        JPanel panel=new JPanel(null);

        JLabel Lab1=new JLabel(details.getTitle());
        JLabel lLab2=new JLabel("申请理由");
        JLabel lLab3=new JLabel("房 间 号");
        JLabel lLab4=new JLabel("所属学院");
        JLabel lLab5=new JLabel("开始时间");
        JLabel lLab6=new JLabel("结束时间");
        JLabel lLab7=new JLabel("申请时间");
        JLabel lLab8=new JLabel("最新进展");

        JLabel rLab2=new JLabel(details.getApplicationReason());
        JLabel rLab3=new JLabel(details.getId());
        JLabel rLab4=new JLabel(details.getCollege());
        JLabel rLab5=new JLabel(details.getStartTime());
        JLabel rLab6=new JLabel(details.getEndTime());
        JLabel rLab7=new JLabel(details.getRecentTime());
        JLabel rLab8=new JLabel(details.getProgress());

        JButton button=new JButton("修改申请");

        setFont(Lab1,lLab2,lLab3,lLab4,lLab5, lLab6,lLab7,
                lLab8,rLab2,rLab3,rLab4,rLab5,rLab6,rLab7,rLab8,button);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });

        Box vBox=Box.createVerticalBox();
        vBox.setBounds(145,4,400,426);

        Box hBox1=Box.createHorizontalBox();
        hBox1.add(Box.createHorizontalStrut(50));

        hBox1.add(Lab1);

        Box hBox2=HBox.creatHBox(30,lLab2,rLab2);
        Box hBox3=HBox.creatHBox(30,lLab3,rLab3);
        Box hBox4=HBox.creatHBox(30,lLab4,rLab4);
        Box hBox5=HBox.creatHBox(30,lLab5,rLab5);
        Box hBox6=HBox.creatHBox(30,lLab6,rLab6);
        Box hBox7=HBox.creatHBox(30,lLab7,rLab7);
        Box hBox8=HBox.creatHBox(30,lLab8,rLab8);

        addStrut(vBox, hBox1, hBox2, hBox3, hBox4);
        addStrut(vBox, hBox5, hBox6, hBox7, hBox8);
        vBox.add(Box.createVerticalStrut(10));
        vBox.add(button);
        panel.add(vBox);

        jf.setContentPane(panel);

    }

    private static void addStrut(Box vBox, Box hBox1, Box hBox2, Box hBox3, Box hBox4) {
        vBox.add(Box.createVerticalStrut(10));
        vBox.add(hBox1);
        vBox.add(Box.createVerticalStrut(10));
        vBox.add(hBox2);
        vBox.add(Box.createVerticalStrut(10));
        vBox.add(hBox3);
        vBox.add(Box.createVerticalStrut(10));
        vBox.add(hBox4);
    }

    public static void setFont(Component... components){
        for(Component component:components){
            component.setFont(new Font("宋体",Font.BOLD,18));
        }
    }
}
